home *** CD-ROM | disk | FTP | other *** search
- Note: All changes are inside a
-
- #ifdef __STORMC__
- ...
- #endif
-
- and/or a
-
- #ifndef __STORMC__
- ...
- #endif
-
- Sources are not included, ask me or Mike Cheng or www.8hz.com (whom i both
- sent it) about them. Hope my changes will be integrated in future general
- versions of the 8Hz Encoder :)
-
- I did not list the changes by Mike Cheng, see his changes-file about them...
- (like support for CDDA...). My version is based on Mike Cheng's sources...
-
- bitstream.c:
- ------------
-
- Replaced K&R Syntax Prototypes by "real" Prototypes, as StormC PPC does not
- like K&R Prototypes.
-
- One example:
-
- int refill_buffer(bs)
- bitstream_t *bs; /* bit stream structure */
-
- is changed to:
-
- #ifndef __STORMC__
- int refill_buffer(bs)
- bitstream_t *bs; /* bit stream structure */
- #else
- int refill_buffer(bitstream_t *bs)
- #endif
-
- I recommend throwing out the K&R Prototypes for future versions to reduce
- the #ifndef's...
-
- fft.c:
- ------
-
- The same like in bitstream.c ...
-
- ieeefloat.c:
- ------------
-
- Changed
-
- #include <stdio.h>
- #include <math.h>
- #include "ieeefloat.h"
-
- to:
-
- #include <stdio.h>
- #include <math.h>
- #include "ieeefloat.h"
- #ifdef __STORMC__
- #include <limits.h>
- #endif
-
- (StormC needs this include)
-
- l3subband.c:
- ------------
-
- Changed
-
- static off[2] = {0,0};
-
- (as this would be a syntax error for StormC)
-
- to:
-
- #ifdef __STORMC__
- static int off[2]={0,0};
- #else
- static off[2] = {0,0};
- #endif
-
- layer3.c:
- ---------
-
- To reduce Contextswitches, i added the possibility to printf the status not every
- frame, but every 50th or 100th or such (Contextswitch are a special phenomen on
- the PowerPC Upgrades of the Amiga-Systems, and they consume time...):
-
- Following the changed code:
-
- #ifdef __STORMC__
- float fskip=100;
- #endif
-
- static void update_status(int frames_processed)
- {
- #ifndef __STORMC__
- printf("\015[Frame %6d of %6ld] (%2.2f%%)",
- frames_processed,config.mpeg.total_frames,
- (float)((float)frames_processed/config.mpeg.total_frames)*100);
- fflush(stdout);
- #else
- int fram=frames_processed;
- fram=fram/fskip;
- if (fram*fskip==frames_processed)
- {
- printf("\015[Frame %6d of %6ld] (%2.2f%%)",
- frames_processed,config.mpeg.total_frames,
- (float)((float)frames_processed/config.mpeg.total_frames)*100);
- fflush(stdout);
- }
- #endif
- }
-
- main.c:
- -------
-
- Changes are:
-
- - concerning the changes in layer3.c a new parameter
- - there were some problems with parameter passing. Under certain circumstances
- incorrect parameters (for example -b without actually giving a bitrate)
- was not detected, i fixed this, but everything inside #ifdef __STORMC__
- to not change the code of the encoder without permission...
-
- Changed parts:
-
- Behind:
-
- #include "types.h"
- #include "error.h"
- #include "wave.h"
- #include "layer3.h"
-
- i inserted:
-
- #ifdef __STORMC__
- extern int fskip;
- #endif
-
- print_usage looks now like:
-
- static void print_usage()
- {
- fprintf(stderr,"USAGE : 8hz-mp3 [options] <infile> <outfile>\n");
- fprintf(stderr,"OPTIONS : -h this help message\n");
- fprintf(stderr," -b <bitrate> set the bitrate, default 128kbit\n");
- fprintf(stderr," -c set copyright flag, default off\n");
- fprintf(stderr," -o set original flag, default off\n");
- #ifdef MFCPCM
- fprintf(stderr," -r force raw PCM reading instead of wav\n");
- fprintf(stderr," -f <Hz> set frequency for PCM reading. Default: 44100\n");
- fprintf(stderr," -x pcm is bigEndian byte order (default: littleEndian)\n");
- #endif /* MFCPCM */
- #ifdef __STORMC__
- fprintf(stderr," -s skip Only print out every skip'th frame (default: 100)\n");
- fprintf(stderr," (To reduce Contextswitches) \n");
- #endif
- fprintf(stderr,"\n");
- }
-
- parse_command now like:
-
- static bool parse_command(int argc, char** argv)
- {
- int i = 0;
-
- if(argc<3) return false;
-
- while(argv[++i][0]=='-')
- switch(argv[i][1])
- {
- #ifndef __STORMC__
- case 'b' : config.mpeg.bitr = atoi(argv[++i]);
- break;
- case 'c' : config.mpeg.copyright = 1;
- break;
- case 'o' : config.mpeg.original = 1;
- break;
- #ifdef MFCPCM
- case 'r' : pcm_switch = 1;
- break;
- case 'f' : pcm_rate = atoi(argv[++i]);
- break;
- case 'x' : pcm_byte_order = 1;
- break;
- #endif /* MFCPCM */
- #else
- case 'b' : if (i+1<argc) config.mpeg.bitr = atoi(argv[++i]);
- break;
- case 's' : if (i+1<argc) fskip=atoi(argv[++i]);
- case 'c' : config.mpeg.copyright = 1;
- break;
- case 'o' : config.mpeg.original = 1;
- break;
- #ifdef MFCPCM
- case 'r' : pcm_switch = 1;
- break;
- case 'f' : if (i+1<argc) pcm_rate = atoi(argv[++i]);
- break;
- case 'x' : pcm_byte_order = 1;
- break;
- #endif /* MFCPCM */
- #endif
- case 'h' :
- default : return false;
- }
-
- if((argc-i)!=2) return false;
- #ifndef __STORMC__
- config.infile = argv[i++];
- config.outfile = argv[i];
- #else
- if (i<argc) config.infile = argv[i++];
- else return false;
- if (i<argc) config.outfile = argv[i];
- #endif
- return true;
- }
-
- portableio.c:
- -------------
-
- like in bitstream.c ...
-
- psy_data.h:
- -----------
-
- As #warning does not exist in StormC:
-
- #ifndef __STORMC__
- #warning HURL, this should be different, lazyness....
- #endif
-
- wave.c:
- -------
-
- Somehow it could not include some constants... don't know if this is a bug in
- the original source or whatever... fixed it by:
-
- #ifdef __STORMC__
- #define RAW_PCM_LOHI 10
- #define RAW_PCM_HILO 11
- #endif
-
- stat.c:
- -------
-
- This source file is new. It is only needed in StormC, as stat() is not existing
- in StormC. Due to #ifdef, this is an empty File for different compilers :)
-
- #ifdef __STORMC__
- #include <dos/dos.h>
- #include <dos/dosextens.h>
- #include <errno.h>
- #include <filedefs.h>
- #include <clib/exec_protos.h>
- #include <time.h>
- #include <exec/types.h>
- #include <libraries/dos.h>
- #include <clib/dos_protos.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/dir.h>
-
- typedef struct FileInfoBlock FIB;
-
- #ifndef UnixToAmigaPath
- #define UnixToAmigaPath(path) path
- #endif
-
- char* strdup(const char* str)
- {
- char* dst = malloc(strlen(str)+1) ;
- if (dst) {
- strcpy(dst, str);
- }
- return dst;
- }
-
- int stat(const char* name, struct stat* stat)
- {
- FileInfoBlock *fib;
- BPTR lock;
- int r = -1;
- struct stat s = {0} ;
-
- *stat = s ;
-
- fib = malloc(sizeof(*fib));
-
- /*
- * If lock fails find file via its parent directory. This is for
- * unix compatibility because you can stat an open write file in unix.
- */
-
- fib->fib_FileName[0] = 0;
-
- if ((lock = Lock((STRPTR)UnixToAmigaPath(name), SHARED_LOCK)) == NULL) {
- extern char* strdup(const char*);
- char *buf = strdup(UnixToAmigaPath(name));
- char *ptr;
- char sk = 0;
-
- for (ptr = buf + strlen(buf); ptr >= buf && *ptr != ':' && *ptr != '/'; --ptr);
- if (ptr < buf || *ptr == ':') {
- ++ptr;
- sk = *ptr;
- }
- *ptr = 0;
- lock = Lock(buf, SHARED_LOCK);
- if (sk)
- *ptr = sk;
- else
- ++ptr;
-
- if (lock == NULL) {
- free(buf);
- errno = ENOENT;
- free(fib);
- return(-1);
- }
- if (Examine(lock, fib)) {
- while (ExNext(lock, fib)) {
- #ifdef TEST
- printf("Compare '%s' '%s'\n", ptr + 1, fib->fib_FileName);
- #endif
- if (stricmp(ptr, fib->fib_FileName) == 0) {
- r = 0;
- break;
- }
- }
- }
- free(buf);
- } else {
- if (Examine(lock, fib))
- r = 0;
- }
- if (lock == NULL) {
- errno = ENOENT;
- free(fib);
- return(-1);
- }
- if (r >= 0) {
- stat->st_size = fib->fib_Size;
- stat->st_ino = (long)((struct FileLock *)BADDR(lock))->fl_Key;
- stat->st_dev = (long)((struct FileLock *)BADDR(lock))->fl_Task;
- stat->st_mode = (fib->fib_DirEntryType > 0) ? S_IFDIR : S_IFREG;
- stat->st_ctime = stat->st_mtime = fib->fib_Date.ds_Days * (1440 * 60) +
- fib->fib_Date.ds_Minute * 60 +
- fib->fib_Date.ds_Tick / 50 ;
- if ((fib->fib_Protection & 8) == 0)
- stat->st_mode |= S_IREAD;
- if ((fib->fib_Protection & 4) == 0)
- stat->st_mode |= S_IWRITE;
- if ((fib->fib_Protection & 2) == 0)
- stat->st_mode |= S_IEXECUTE;
- if (fib->fib_Protection & 0x40)
- stat->st_mode |= S_IEXECUTE;
- }
- UnLock(lock);
- if (r < 0)
- errno = ENOENT;
- free(fib);
- return(r);
- }
- #endif
-
- Next i used some VERY optimized math-functions i got from Andreas Heumann, which
- are done in 100% PPC ASM, replacing some occurences of exp, sqrt, sin, cos, pow
- and atan2 by exp_ppc, sqrt_ppc, sin_ppc, cos_ppc, pow_ppc and atan2_ppc, controlled
- by a new #define PPCMATH. This gave another 10% speedup :) Now my 18 second
- test sample is done in 39 seconds on a 150 MHz machine with -q set to 100.
- On a 233 MHz machine it should be done in 25 seconds, which is VERY close to
- real-time encoding :)
-
- At the end, i created a project file:
-
- Additionally to a default PPC-Executable Project file i added:
-
- In Preprocessor:
-
- BS_FORMAT=BINARY
- HUGE_VAL=MAXDOUBLE
- __STORMC__=1
- MFCPCM=1
-
- In Options:
-
- Don't use Inline (well, only as i always specified this... does not make sense
- i guess... could be left out :) )
-
- Indirect Data
-
- In Program Start:
- Stack: 300 KB
-
- (If you start it from the project environment)
-
- That is finally all :)
-
- Steffen Haeuser
- MagicSN@Birdland.es.bawue.de
-
-
-
-